package pl.mdziedzic.unittest;

import java.util.Arrays;
import java.util.Collection;

import junit.framework.Assert;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.DisplayAction;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

@RunWith(value = Parameterized.class)
public class testBananScrum extends seleniumBase {

	private final Parametr2 param;

	public testBananScrum(Parametr2 param) {
		this.param = param;
	}

	public void testJunitBananScrumComLogin(Parametr2 parametr)
			throws Exception {
		driver.get("http://demo.bananascrum.com/login");

		clear(By.id("login"));
		sendKeys(By.id("login"), parametr.getLogin());
		clear(By.id("password"));
		sendKeys(By.id("password"), parametr.getPassword());
		click(By.name("commit"));

		Assert.assertEquals(driver.findElement(By.id("flash")).getText(),
				"Login failed Type user 'admin' with password 'password'");

		// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
	}

//	@Test
//	public void shouldCheckLogin() throws Exception {
//
//		try {
//			testJunitBananScrumComLogin(param);
//		} catch (Exception e) {
//			// TODO: handle exception
//			return;
//		}
//
//	}

	@Test
	public void loginCorrect() throws Exception{
		driver.get("http://demo.bananascrum.com/login");
		
		clear(By.id("login"));
		sendKeys(By.id("login"), "admin");
		clear(By.id("password"));
		sendKeys(By.id("password"), "password");
		click(By.name("commit"));
		WebElement element = driver.findElement(By.id("flash"));
		Assert.assertEquals( element.isDisplayed(), true);
		
//		WebDriverWait wait = new WebDriverWait(driver, 5);
//		wait.until(new ExpectedCondition<Boolean>(){
//			{
//				@Override
//				public WebElement(WebDriver d){
//					
//				}
//				
//		}
//		});
	}
	@Parameters
	public static Collection<Object[]> data() {
		Object[][] data = new Object[][] { { new Parametr2("aaa", "aaa") },
				{ new Parametr2("admin", "aaa") },
				{ new Parametr2("aaa", "admin") } };
		return Arrays.asList(data);
	}

}

class Parametr2 {

	private String login;
	private String password;

	public Parametr2(String login, String password) {
		this.login = login;
		this.password = password;
	}

	public String getLogin() {
		return login;
	}

	public String getPassword() {
		return password;
	}

	@Override
	public String toString() {
		return "Parametr [login=" + login + ", Password=" + password + "]";
	}
}
